<?
    include "../../common.php" ;
    $opt = $_POST['opt'] ;
    $arr = [] ;
    if( $opt == 'getList' ){
        $page = $_POST['page'] ; 
        $perPage = $_POST['perPage'] ; 
        $pageSt = ( $page - 1 ) * $perPage ; 
        $sql = "SELECT * FROM `users` WHERE ulevel = 3 AND is_delete = 1 ORDER BY id ASC LIMIT {$pageSt} , {$perPage}" ;
        $res = mysqli_query($link,$sql);
        while( $one = mysqli_fetch_assoc($res) ){
            $arr[] = $one ; 
        }
    }
    if( $opt == 'updSel' ){
        $id = $_POST['id'] ; 
        $sql = "SELECT * FROM `users` WHERE id = {$id}" ;
        $res = mysqli_query($link,$sql);
        if( mysqli_affected_rows($link) ){
            $one = mysqli_fetch_assoc($res);
            $arr = $one ; 
        }
    }
    if( $opt == 'upd' ){
        $tel = $_POST['tel'];
        $pwd = $_POST['pwd'];
        $ulevel = $_POST['ulevel'];
        $id = $_POST['id'];
        $sql = "UPDATE `users` SET tel = {$tel} , pwd = '{$pwd}' , ulevel = {$ulevel} WHERE id = {$id}" ;
        $res = mysqli_query($link,$sql);
        if( $res ){
            $arr['status'] = 1 ;
            $arr['info'] = '修改成功!' ;
        } else {
            $arr['status'] = 0 ;
            $arr['info'] = '操作失败!' ; 
        }
    }
    if( $opt == 'del' ){
        $id = $_POST['id'] ; 
        $sql = "UPDATE `users` SET is_delete = 2 WHERE id = {$id}" ;
        $res = mysqli_query($link,$sql);
        if( mysqli_affected_rows($link) ){
            $arr['status'] = 1 ; 
            $arr['info'] = '删除成功!' ;
        } else {
            $arr['status'] = 0 ; 
            $arr['info'] = '操作失败!' ;
        }
    }
    if( $opt == 'getPageNum' ){
        $perPage = $_POST['perPage'] ;
        $sql = "SELECT count(id) AS c FROM `users` WHERE ulevel = 3 AND is_delete = 1 " ; 
        $res = mysqli_query($link,$sql);
        if( mysqli_affected_rows($link) ){
            $one = mysqli_fetch_assoc($res);
            $arr['totalPage'] = ceil($one['c'] / 10) ;
        }
    }
    echo json_encode($arr);
?>